<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="utf-8" />
        <title>PythonTutorials - python</title>
        <link rel="stylesheet" href="/theme/css/main.css" />

        <!--[if IE]>
            <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
</head>

<body id="index" class="home">
        <header id="banner" class="body">
                <h1><a href="/">PythonTutorials </a></h1>
                <nav><ul>
                    <li><a href="/category/cpp.html">cpp</a></li>
                    <li class="active"><a href="/category/python.html">python</a></li>
                </ul>
                </nav>
        </header><!-- /#banner -->

                <section id="content" class="body">
                    <ol id="posts-list" class="hfeed" start="2">
            <li><article class="hentry">
                <header>
                    <h1><a href="/Part.2.D.7-tdd.html" rel="bookmark"
                           title="Permalink to Part.2.D.7-tdd">Part.2.D.7-tdd</a></h1>
                </header>

                <div class="entry-content">
<footer class="post-info">
        <span>Mon 06 April 2020</span>
<span>| tags: <a href="/tag/python.html">python</a><a href="/tag/progarmming.html">progarmming</a><a href="/tag/excel.html">Excel</a></span>
</footer><!-- /.post-info -->                <h1>测试驱动的开发</h1>
<p>写一个函数，或者写一个程序，换一种说法，其实就是 “实现一个算法” —— 而所谓的 “算法”，Wikipedia 上的定义是这样的：</p>
<blockquote>
<p>In mathematics and computer science, an <strong>algorithm</strong> is an unambiguous specification of how to solve a class of problems. Algorithms can perform <em>calculation</em>, <em>data processing</em>, and <em>automated reasoning tasks</em>.</p>
</blockquote>
<p>“算法”，其实没多神秘，就是 “解决问题的步骤” 而已。</p>
<p>在第二部分的第一章里，我们看过一个判断是否为闰年的函数：</p>
<blockquote>
<p>让我们写个判断闰年年份的函数，取名为 is_leap()，它接收一个年份为参数 …</p></blockquote>
                <a class="readmore" href="/Part.2.D.7-tdd.html">read more</a>
                </div><!-- /.entry-content -->
            </article></li>

            <li><article class="hentry">
                <header>
                    <h1><a href="/Part.2.D.8-main.html" rel="bookmark"
                           title="Permalink to Part.2.D.8-main">Part.2.D.8-main</a></h1>
                </header>

                <div class="entry-content">
<footer class="post-info">
        <span>Mon 06 April 2020</span>
<span>| tags: <a href="/tag/python.html">python</a><a href="/tag/progarmming.html">progarmming</a><a href="/tag/excel.html">Excel</a></span>
</footer><!-- /.post-info -->                <h1>可执行的 Python 文件</h1>
<p>理论上来讲，你最终可以把任何一个程序，无论大小，都封装（或者囊括）到仅仅一个函数之中。按照惯例（Convention），这个函数的名称叫做 <code>main()</code>：</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">routine_1</span><span class="p">():</span>
    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;Routine 1 done.&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">routine_2</span><span class="p">():</span>
    <span class="n">sub_routine_1</span><span class="p">()</span>
    <span class="n">sub_routine_2</span><span class="p">()</span>
    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;Routine 2 done.&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">sub_routine_1</span><span class="p">():</span>
    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;Sub-routine 1 done.&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">sub_routine_2</span><span class="p">():</span>
    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;Sub-routine 2 done.&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">main</span><span class="p">():</span>
    <span class="n">routine_1</span><span class="p">()</span>
    <span class="n">routine_2</span><span class="p">()</span>
    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;This is the end of the …</span></pre></div>
                <a class="readmore" href="/Part.2.D.8-main.html">read more</a>
                </div><!-- /.entry-content -->
            </article></li>

            <li><article class="hentry">
                <header>
                    <h1><a href="/Part.2.E.deliberate-thinking.html" rel="bookmark"
                           title="Permalink to Part.2.E.deliberate-thinking">Part.2.E.deliberate-thinking</a></h1>
                </header>

                <div class="entry-content">
<footer class="post-info">
        <span>Mon 06 April 2020</span>
<span>| tags: <a href="/tag/python.html">python</a><a href="/tag/progarmming.html">progarmming</a><a href="/tag/excel.html">Excel</a></span>
</footer><!-- /.post-info -->                <h1>刻意思考</h1>
<p>随着时间的推移，你会体会到它的威力：</p>
<blockquote>
<p>刻意思考哪儿需要刻意练习</p>
</blockquote>
<p>只不过是一句话而已，却因知道或不知道，竟然会逐渐形成天壤之别的差异，也是神奇。</p>
<p>刻意思考，就是所谓的琢磨。琢磨这事，一旦开始就简单得要死，可无从下手的时候就神秘无比。让我们再看一个 “刻意思考” —— 即，琢磨 —— 的应用领域：</p>
<blockquote>
<p><strong>这东西能用在哪儿呢？</strong></p>
</blockquote>
<p>很多人学了却没怎么练，有一个很现实的原因 —— 没什么地方用得上。</p>
<p>这也怪我们的应试教育，大学前上 12 年学，“学”（更多是被逼的）的绝大多数东西，只有一个能够切实体会到的用处，考试 —— 中考、高考，以及以它们为目标的无数 “模考”…… 于是，反过来，不管学什么东西，除了考试之外，几乎无法想象其他的用处。</p>
<p>一旦我们启动了对某项技能的自学之后，在那过程中，最具价值的刻意思考就是，时时刻刻琢磨 “这东西能用在哪儿呢？”</p>
<p>比如，当你看到字符串的 Methods 中有一个 <code>str …</code></p>
                <a class="readmore" href="/Part.2.E.deliberate-thinking.html">read more</a>
                </div><!-- /.entry-content -->
            </article></li>
            </ol><!-- /#posts-list -->
<p class="paginator">
        <a href="/category/python8.html">&laquo;</a>
    Page 9 / 17
        <a href="/category/python10.html">&raquo;</a>
</p>
            </section><!-- /#content -->
        <section id="extras" class="body">
                <div class="blogroll">
                        <h2>blogroll</h2>
                        <ul>
                            <li><a href="http://getpelican.com/">Pelican</a></li>
                            <li><a href="http://python.org/">Python.org</a></li>
                            <li><a href="http://jinja.pocoo.org/">Jinja2</a></li>
                            <li><a href="#">You can modify those links in your config file</a></li>
                        </ul>
                </div><!-- /.blogroll -->
                <div class="social">
                        <h2>social</h2>
                        <ul>

                            <li><a href="#">You can add links in your config file</a></li>
                            <li><a href="#">Another social link</a></li>
                        </ul>
                </div><!-- /.social -->
        </section><!-- /#extras -->

        <footer id="contentinfo" class="body">
                <p>Powered by <a href="http://www.maxiaoan.com/">Maxiaoan</a></p>
        </footer><!-- /#contentinfo -->

</body>
</html>